package com.mezz.bones.framework.id.generator.domain.dto;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serializable;

/**
 * ID区间DTO
 * 用于批量获取ID时返回ID区间信息
 *
 * @author WMS System
 * @since 1.0.0
 */
@Data
@NoArgsConstructor
@AllArgsConstructor
public class IdRangeDto implements Serializable {

    private static final long serialVersionUID = 1L;

    private long startId;

    private long endId;

    private int size;

    /**
     * 构造方法
     * @param startId 起始ID
     * @param size 区间大小
     */
    public IdRangeDto(long startId, int size) {
        this.startId = startId;
        this.size = size;
        this.endId = startId + size - 1;
    }

    /**
     * 检查ID是否在区间内
     * @param id 要检查的ID
     * @return 是否在区间内
     */
    public boolean contains(long id) {
        return id >= startId && id <= endId;
    }

    /**
     * 获取区间内的所有ID数量
     * @return ID数量
     */
    public int getCount() {
        return (int) (endId - startId + 1);
    }
}